package view.nn.com.myapplication.utils;

import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

/**
 * Created by esri on 2017/2/18.
 */

public class CountDown {

    private Handler handler;
    private int timeCount;
    private TextView countTextView;

    public CountDown(TextView textView) {
        this.countTextView = textView;
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                timeCount = timeCount - 1;
                countTextView.setText(timeCount + "");
                if (timeCount > 0) {
                    handler.sendEmptyMessageDelayed(0, 1000);
                }
            }
        };

    }

    public void excute(int timeInt) {
        //set count down time
        this.timeCount = timeInt;
        this.countTextView.setText(timeInt + "");
        handler.sendEmptyMessageDelayed(0, 2000);
    }
}
